// 物品申请

function query_apply() {
	
	var parm = $('#queryApplyForm').serialize();
	var url = create_url('apply-query');
	
	$.ajax({type:'POST', url:url, data:parm,
		success: function (result) {
			$('#page_content').html(result);
			swiperNested1.reInit();			// 刷新样式计算
		},
		error:function (e) {
			
		}
	});
}

function addRow_apply() {
	
	var loadMore = $('#addRow');
	var i = parseInt(loadMore.attr('i'));
	
	var item = $("#ul_rep").find('.rep').clone(true);
	item.find('.name').attr({'name':'adList[' + i + '].gn'}).end()
		.find('.count').attr({'name':'adList[' + i + '].count'}).end();
	
	$('#apply_item').append(item);
	loadMore.attr('i', ++i);
	swiperNested1.reInit();			// 刷新样式计算
}

function delRow_apply(jqObj) {
	if (confirm("确定要删除本条明细？")) {
		if ($('#apply_item').find('.rep').length > 1)
			jqObj.parents('.rep').remove();
		else 
			alert('至少要有一条明细');
	}
	swiperNested1.reInit();			// 刷新样式计算
}

// 拼接标题
function subTitle_apply() {
	var title = "";
	var temp = "";
	var tempName = "";
	var tempCount = "";
	$('#apply_item').find('.rep').each(function (e) {
		tempName = $(this).find('.name').val(); 
		tempCount = $(this).find('.count').val();
		
		if ('' != tempName && undefined != tempName && '' != tempCount && undefined != tempCount) {
			temp = tempName + '(';
			temp += tempCount + ') '
		}
		
		if (title.length + temp.length < 80) {
			title += temp; 
			temp = "";
		} else {
			title += '...';
			return false;
		}
	});
	
	$('#title_applye').val(title);
}

function save_apply() {
	var parm = $('#editApplyForm').serialize();
	var url = create_url('apply-save');
	$.ajax({type:'POST', url:url, data:parm, 
		success: function (result) {
			if ('success' == result) {
				alert('保存成功');
				sys_load_handl('apply');
			} else if ('error' == result) 
				alert('保存失败');
			else if ('parameter_error' == result)
				alert('没有可以保存的数据');
			else
				alert('保存失败');
		},
		error:function (e) {
			alert('服务器错误');
		}
	});
}

function shield_apply(code) {
	if (!confirm("确定要删除该条信息吗？")) {
		return false;
	}
	
	var parm = {'code':code};
	var url = create_url('apply-shield');
	$.ajax({type:'POST', url:url, data:parm, 
		success: function (result) {
			if ('success' == result) {
				alert('删除成功');
				sys_load_handl('apply');
			} else if ('error' == result) 
				alert('删除失败');
			else if ('failure' == result)
				alert('已经被审核通过了，不能删除');
			else
				alert('删除失败');
		},
		error:function (e) {
			alert('服务器错误');
		}
	});
}
